home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_069 / conman / handler.asm < prev    next >
Assembly Source File  |  1992-05-06  |  4KB  |  107 lines

  1. * === handler.asm ==========================================================
  2. *
  3. * Copyright (c) 1987 by William S. Hawes
  4. *
  5. * Distribute freely (but please leave the notice intact ...)
  6. *
  7. * ======================================================================
  8. *
  9. * This program functions as a "bootstrap loader" for DOS handler processes.
  10. * It begins life as an ersatz-BCPL process, loaded automatically by DOS
  11. * when your handler is opened.  It opens your handler, created as
  12. * a standard shared library, and then transfers to its main entry point.
  13. *
  14. * The main idea here is to allow handlers to be developed without going
  15. * through the nonsense of creating BCPL-style modules.  It is difficult
  16. * even in assembler to get the module to look right -- it took numerous
  17. * tries to get even this short program working.  The basic problem is that
  18. * every "hunk" created by your program must look like the BCPL model:
  19. * preceded by a long-word count, and followed by the global vector table.
  20. * The long-word count requires that you assemble the whole program at once
  21. * to get the total size, which makes for some very long assembles.
  22. *
  23. * Even after your program looks right, the trouble is only beginning.
  24. * Your code may look like BCPL, but the program libraries used in
  25. * linking the handler may contribute hunks that aren't BCPL-ish.
  26. * I got around this by including the EXEC library offset definitions in
  27. * the include file "fix.i", so I don't even need Amiga.lib in my link.
  28. *
  29. * By developing the handler as standard shared library, you can work in
  30. * a less ascetic development environment and still use DOS's automatic
  31. * loading capabilites.
  32. *
  33. * One nice side-effect of building handlers this way is that the
  34. * handler library can be unloaded by the system if memory gets tight.
  35. * Each invocation of the handler opens and eventually closes the library,
  36. * so the library can be swapped out if the handler isn't open at the time.
  37. * This is partial compensation for the lack of proper DOS mechanisms to
  38. * unload device handlers when they are no longer being used ...
  39.  
  40. * After assembling and linking this program, install it as a handler in the
  41. * usual way (either by the MOUNT command or by patching the device node).
  42. * Note that if a simple entry-point convention were adopted, this program
  43. * could work for any handler, requiring only the name of the specific
  44. * library to be opened.  Why, there could even be a function called
  45. * "OpenHandler" ... but then, no one get to use BCPL anymore.
  46. *
  47. *                                      -- WSH  (617) 568-8695
  48.  
  49.  
  50.          INCLUDE  "chlib.i"            ; definitions for your handler
  51.          INCLUDE  "fix.i"              ; offsets derived from "exec_lib.i"
  52.  
  53.          INCLUDE  "libraries/dos.i"
  54.          INCLUDE  "libraries/dosextens.i"
  55.  
  56. _AbsExecBase   EQU   4
  57.  
  58.          CNOP     0,4
  59. StartModule:
  60.          dc.l     (EndModule-StartModule)/4
  61.  
  62. start:   movea.l  _AbsExecBase,a6
  63.          move.l   d1,d4                ; save packet (BPTR)
  64.  
  65.          lea      CHLib(pc),a1         ; library name
  66.          moveq    #CHLVERS,d0          ; version number
  67.          CALLSYS  OpenLibrary
  68.          tst.l    d0                   ; opened?
  69.          beq.s    CleanUp              ; no??
  70.          movea.l  d0,a5
  71.  
  72.          ; Call the console handler entry point
  73.  
  74.          move.l   d4,d1                ; startup packet
  75.          exg      a5,a6
  76.          CALLSYS  CHEntry
  77.          exg      a5,a6
  78.  
  79.          movea.l  a5,a1
  80.          CALLSYS  CloseLibrary
  81.          bra.s    Exit
  82.  
  83.          ; Groan ... if we can't open the library, I can't even use the
  84.          ; "ReturnPkt" function defined there ... must repeat it here.
  85.  
  86. CleanUp:
  87.          lsl.l    #2,d4
  88.          movea.l  d4,a0                ; DOS packet
  89.          clr.l    dp_Res1(a0)          ; FALSE return
  90.          clr.l    dp_Res2(a0)          ; use an error code, maybe?
  91.          movea.l  dp_Link(a0),a1       ; EXEC message
  92.          movea.l  dp_Port(a0),a0       ; replyport (??#@!)
  93.          CALLSYS  PutMsg
  94.  
  95. Exit:    rts
  96.  
  97. CHLib    CHLNAME                       ; library name
  98.  
  99.          CNOP     0,4
  100.          dc.l     0                    ; end marker
  101.          dc.l     1                    ; global defined
  102.          dc.l     4                    ; offset
  103.          dc.l     1                    ; maximum global
  104. EndModule:
  105.  
  106.          END
  107.